﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_TraTradeTotalAdd : System.Web.UI.Page, HZ.MBSM.BLL.TraDes
{
    int CWProduct;
    string StrSql;
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            CWProduct = SysFun.ToInt(SysFun.IsSQL(Request.QueryString["projectid"]));

        }
         if (IsPostBack)
        {
            Success();
        }

    }

  
    protected void Button3_Click(object sender, EventArgs e)
    {
        Db db = new Db();
        System.Data.IDataReader dr;
        StrSql = "Select Top 10 * From project_bid where projectid=" + CWProduct.ToString() + " and isbid='1'";//检查是否已经投标结束
        dr = db.DataReader(StrSql);
        if (dr.Read())
        {

        }
        else
        {
            Response.Write("<script>window.alert('对不起，没有中标数据，该功能不能使用');</script>");
            Response.Write("<script>window.location.href='Compete.aspx?projectid=" + CWProduct + "'</script>");
        }
        dr.Close();
        //检查是否已经完成
        StrSql = "Select Top 10 * From SupplyPlan_Goods Where Projectid=" + CWProduct + " and GoodsState=0";
        dr = db.DataReader(StrSql);
        if (dr.Read())
        {
            dr.Close();
            dr.Dispose();
            Response.Write("<script>window.alert('已经导入过了，请执行其他步骤！');</script>");
            Msg1.Text = "中标数据已经导入过了";
            //Response.Write("<script>window.location.href='TraTradeTotalAdd.aspx?projectid=" + CWProduct + "'</script>");
            //Response.End();
        }
        else
        {
            dr.Close();
            dr.Dispose();
            //直接将竟价和限价的中标结果导入到配送目录表中
            StrSql = "insert into SupplyPlan_Goods( ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName,BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC,CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_PS, CompanyName_PS,BidPrice, GoodsState,UserCode_TB,UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName) select ProjectId, ProductId, ProductName, MedicineModel, Outlookc, ProductCode, BidTableName, BidTableType, BidTableOutlookc, GoodsId, GoodsName, QualityLevels, Pack, Factor, PackUnit, AccountId_SC, CompanyName_SC, AccountId_Agent, CompanyName_Agent, AccountId_TB, CompanyName_TB, AccountId_PS, CompanyName_PS,BidPrice,'0',UserCode_TB,UserCode_PS,UserCode_SC,FrontSortId,FrontSortName,Sortid,SortName  from TradeDataList where projectid=" + CWProduct.ToString() + " and isbid='1' and (status=0 or status=1) ";
            db.Command(StrSql);           
        }
        db.Close();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Success();
      
       
    }
    public void Success()
    {
     string CStatus="";
        switch (DropDownList1.SelectedValue)
        {
            case "全部":
                CStatus="'1' or Status='0' or Status is null ";
                break;
            case "限价中标":
                CStatus = "'0' ";
                break;
            case "竞价中标": 
                CStatus = "'1'";
                break;
        }
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "BidGoods_View";                                               //表名，可以多个表关联
        dbPage.Key = "BidId";
        //该查询可以唯一表示记录的字段，该属性必须设置且只能有一个唯一标识字段
        dbPage.Where = " projectid=" + CWProduct + " and (Status="+CStatus+") and isbid='1'";
       
        dbPage.SelectField = " BidId,status,salername,ProductName,MedicineModel,OutLookC,factoryName,ProductCode,QualityLevels,SPPrice,BidPrice ";//可以不设，默认为“*”
        
        dbPage.OrderBy = "ProductName,BidId,";                                //排序字段，可以不输入。不输入时以 Key 作为排序字段
        
        dbPage.PageIndex = SysFun.ToInt(Request.QueryString["PG"]);
        
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //设置需要查询第几页
        dbPage.PageSize = 30;                                              //设置每页显示多少条记录
            
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        sb.Append("<p align='center'><font color='blue' size='3'>中标商品一览表</font></p>");
        sb.Append("<table border=1 cellpadding='0' cellspacing='0'   style='border-collapse: collapse' bordercolor='#111111' width='98%' height='128'>");
        sb.Append("<tr style='font-weight:bold'>");
        sb.Append("<td nowrap align=center>投标人</td>");
        sb.Append("<td nowrap align=center>通用名</td>");
        sb.Append("<td nowrap align=center>剂型</td>");
        sb.Append("<td nowrap align=center>规格</td>");
        sb.Append("<td align='center' nowrap>生产企业</td>");
        sb.Append("<td nowrap align=center>药品编码</td>");
        sb.Append("<td nowrap align=center>质量层次</td>");
        sb.Append("<td align='center' nowrap>包装投标报价</td>");
        sb.Append("<td align='center' nowrap>中标价</td>");
        sb.Append("<td align='center' nowrap>类型</td>");
        sb.Append("</tr>");
        int intNum = 0;
        string levels = "", results = "";

        while (dr.Read())
        {
            intNum++;
            levels = SysFun.ToTrim(dr["QualityLevels"]);
            switch (levels)
            {
                case "0":
                    levels = "普通GMP药品";
                    break;
                case "1":
                    levels = "专利药品";
                    break;
                case "2":
                    levels = "1999年以来获得国家科学技术奖的药品";
                    break;
                case "3":
                    levels = "国家一类新药";
                    break;
                case "4":
                    levels = "原研制药品";
                    break;
                case "5":
                    levels = "单独定价药品";
                    break;
                case "6":
                    levels = "优质优价中成药";
                    break;
                case "7":
                    levels = "全国医药工业百强企业的药品";
                    break;
                case "8":
                    levels = "中药保护品种";
                    break;
                case "9":
                    levels = "欧美认证药品";
                    break;
            }

            results = SysFun.ToTrim(dr["Status"]);
            switch (results)
            {
                case "1":
                    results = "竞价成功";
                    break;
                case "0":
                    results = "限价成功";
                    break;
            }


            sb.Append("<tr>");
            sb.Append("<td>" + SysFun.ToTrim(dr["salername"]) + "</td>");
            sb.Append("<td>" + SysFun.ToTrim(dr["productname"]) + "</td>");
            sb.Append("<td>" + SysFun.ToTrim(dr["medicinemodel"]) + "</td>");
            sb.Append("<td>" + SysFun.ToTrim(dr["outlookc"]) + "</td>");
            sb.Append("<td>" + SysFun.ToTrim(dr["factoryname"]) + "</td>");
            sb.Append("<td>" + SysFun.ToTrim(dr["ProductCode"]) + "</td>");
            sb.Append("<td>" + levels + "</td>");
            sb.Append("<td>" + SysFun.ToTrim(dr["SPPrice"]) + "</td>");
            sb.Append("<td>" +  SysFun.ToTrim(dr["BidPrice"])  + "</td>");
            sb.Append("<td>" + SysFun.ToTrim(results) + "</td>");        
            sb.Append("</tr>");
        }


        sb.Append("</table>");
        Label1.Text = sb.ToString();
        this.DbPageFlip1.DbPage = dbPage;
        dbPage.Db.Close();
        dr.Close();
        dr.Dispose();
        db.Close();
    }

    
    protected void Button4_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.location.href='TraTradeDataList.aspx?projectid=" + CWProduct + "'</script>");
    }
    #region TraDes 成员

    public string Name
    {
        get { return "导入限价竟价采购目录"; }
    }

    public string Describe
    {
        get { return ""; }
    }

    public string ParentName
    {
        get { return "挂网目录管理"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
            return _AccountType;
        }
    }

    #endregion
    
}
